function findWarehouseType(warehouseType,arr){	
	$.ajax({
	    type : "post",
	    url : ctx+"/sys/dict/findWarehouseTypeByTypeList?typeList="+arr, //此次url改为真正需要的url
	    success : function(data) {						    	
	    	var optionstring = "<option value=''>"+"--请选择--"+"</option>";  
	    	if(data!=null){
		    	for(var i=0;i<data.length;i++){
		    		 optionstring += "<option value=\"" + data[i].value+ "\">" +data[i].label+ "</option>";
		    	}
	    	}							    	
	    	$("#"+warehouseType).html(optionstring); 
	    }
});
}

function findWarehouse(warehouseId,warehouseType) {
    $("#"+warehouseId).empty();				    	
		var type=$("#"+warehouseType).val();
		$.ajax({
		    type : "post",
		    url : ctx+"/warehouse/warehouse/findByType?warehouseType="+type, //此次url改为真正需要的url
		    success : function(data) {						    	
		    	var optionstring ="<option value=''></option>";
		    	if(data!=null){
			    	for(var i=0;i<data.length;i++){
			    		 optionstring += "<option value=\"" + data[i].id+ "\">" +data[i].warehouseName+ "</option>";
			    	}
		    	}							    	
		    	$("#"+warehouseId).html(optionstring); 
		    }
	});
};

function check(id,arr){
	$('#'+id).bootstrapTable({		 
		  //请求方法
             method: 'get',
             //类型json
             dataType: "json",
             //显示刷新按钮
             showRefresh: false,
             //显示切换手机试图按钮
             showToggle:false,
             //显示 内容列下拉框
  	       showColumns: false,
  	       //显示到处按钮
  	       showExport: false,
  	       //显示切换分页按钮
  	       showPaginationSwitch: false,
  	       //最低显示2行
  	       minimumCountColumns: 2,
             //是否显示行间隔色
             striped: true,
             //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）     
             cache: false,    
             //是否显示分页（*）  
             pagination: false,   
              //排序方式 
             sortOrder: "asc",  
             //初始化加载第一页，默认第一页
             	pageNumber:1,   
             //每页的记录行数（*）   
            pageSize: 10,  
             //可供选择的每页的行数（*）    
             pageList: [10, 25, 50, 100],
             //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据  
             url:ctx+"/resource/findResourceDetailByIds?ids="+arr,
             //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
             //queryParamsType:'',   
             ////查询参数,每次调用是会带上这个参数，可自定义                         
             queryParams : function(params) {
            	 var searchParam = $("#searchForm").serializeJSON();
                	searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
                	searchParam.pageSize = params.limit === undefined? -1 : params.limit;
                	searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+  params.order;
                    return searchParam;
             },
             //分页方式：client客户端分页，server服务端分页（*）
             sidePagination: "server",
             contextMenuTrigger:"right",//pc端 按右键弹出菜单
             contextMenuTriggerMobile:"press",//手机端 弹出菜单，click：单击， press：长按。
             contextMenu: '#context-menu',       
            onClickRow: function(row, $el){
             },
             columns: [{
            	 field: 'state',
 		        title: '异常状态',
 		        sortable: true	
		    }
			,{
		        field: 'id',
		        title: '资源编号',
		        sortable: true	       
		    }
			,{
		        field: 'productName',
		        title: 'sku',
		        sortable: true	       
		    },{
		        field: 'firstType',
		        title: '一级类目',
		        sortable: true	       
		    },{
		        field: 'secondType',
		        title: '二级类目',
		        sortable: true	       
		    },{
		        field: 'thirdType',
		        title: '三级类目',
		        sortable: true	       
		    },{
		        field: 'warehouseName',
		        title: '仓库名称',
		        sortable: true	       
		    },{
		        field: 'warehouseTypeName',
		        title: '仓库类型',
		        sortable: true	       
		    },{
		        field: 'evidenceLock',
		        title: '凭据锁',
		        sortable: true	
		        ,formatter:function(value, row , index){
             	   if (row.evidenceLock == "0") {
                        return "解锁";
                    }  
             	   if (row.evidenceLock == "1") {
                        return "锁定";
                    }  
		         }
		    }	
		     ]
		
		});
}
$(function () {
var ws ;
var arr=[];
var json=new Array();
var ip;
$("#conn").click(function(){	
	$("#phoneConn").attr({"disabled":"disabled"});
	$("#conn").css({'background-color':'black'});
	$.ajax({
	    type : "post",
	    url : ctx+"/statistics/getIp?label="+"wired", //此次url改为真正需要的url
	    success : function(data) {						    	
	    	ip=data;
	    	ws = new WebSocket("ws://"+ip+":54321/RFID/");
	    	ws.onopen = function()
	    	{
	    	   // Web Socket 已连接上，使用 send() 方法发送数据
	    	   //ws.send("发送数据");
	    	   $("#isConnect").html("true");	   
	    	}; 
	    	ws.onmessage = function (evt) 
	    	{ 
	    	   var received_msg = evt.data;
	    		if(arr.indexOf(received_msg)==-1){
	    		   arr.push(received_msg)
	    		   $("#resourceIds").empty();
	    		   $("#resourceIds").val(arr.join(','));
	    		   var obj=new Object()
	    		   obj.id=received_msg;
	    		   json.push(obj);
	    		   $("#checkResourceTable").bootstrapTable('destroy');
	    		   $('#checkResourceTable').bootstrapTable({
	    			    data:json,
	    			    columns: [{
	    		       	 field: 'state',
	    			        title: '异常状态',
	    			        sortable: true	
	    			    }
	    				,{
	    			        field: 'id',
	    			        title: '资源编号',
	    			        sortable: true	       
	    			    }
	    				,{
	    			        field: 'productName',
	    			        title: 'sku',
	    			        sortable: true	       
	    			    },{
	    			        field: 'firstType',
	    			        title: '一级类目',
	    			        sortable: true	       
	    			    },{
	    			        field: 'secondType',
	    			        title: '二级类目',
	    			        sortable: true	       
	    			    },{
	    			        field: 'thirdType',
	    			        title: '三级类目',
	    			        sortable: true	       
	    			    },{
	    			        field: 'warehouseName',
	    			        title: '仓库名称',
	    			        sortable: true	       
	    			    },{
	    			        field: 'warehouseTypeName',
	    			        title: '仓库类型',
	    			        sortable: true	       
	    			    },{
	    			        field: 'evidenceLock',
	    			        title: '凭据锁',
	    			        sortable: true	
	    			        ,formatter:function(value, row , index){
	    		        	   if (row.evidenceLock == "0") {
	    		                   return "解锁";
	    		               }  
	    		        	   if (row.evidenceLock == "1") {
	    		                   return "锁定";
	    		               }  
	    			         }
	    			    }	
	    			     ]
	    			});
	    		   
	    		}
	    	};
	    	ws.onclose = function (evt) 
	    	{ 
	    		var arr=$("#resourceIds").val().split(",");
	    		$("#checkResourceTable").bootstrapTable('destroy');
	    		var data1=["总量","扫描正常","扫描异常"];
	    		var data2=[];
	    		var data3=[];
	    		var data4=[];
	    		 
	    		 $.ajax({
	    			    url:ctx+"/resource/findResourceCountByIds?ids="+arr,
	    			    type:"post",	   
	    			    success:function(data){
	    			    	if(data !=null && data != ''){
	    			    		var obj1=new Object();
	    			    		var obj2=new Object();
	    			    		var obj3=new Object();
	    			    		obj1.name="扫描正常";
	    			    		obj1.value=data.totalCurrectCount;
	    			    		obj2.name="扫描异常";
	    			    		obj2.value=data.totalErrorCount;
	    			    		obj3.name="扫描总量";
	    			    		obj3.value=data.totalCount;
	    			    		data2.push(obj1);
	    			    		data2.push(obj2);
	    			    		data3.push(obj3);
	    			    		var resCount=data.resourceList;
	    			    		if(resCount != null && resCount != ''){
	    			    			for(var i=0;i<resCount.length;i++){
	    			    				data1.push(resCount[i].productName);
	    			    				var obj4=new Object();
	    			    				obj4.name=resCount[i].productName;
	    					    		obj4.value=resCount[i].count;
	    					    		data4.push(obj4);
	    			    			}
	    			    		}
	    			    		var myChart = echarts.init(document.getElementById('main'));
	    			    		 option = {
	    			    				    tooltip: {
	    			    				        trigger: 'item',
	    			    				        formatter: "{b}: {c} ({d}%)"
	    			    				    },
	    			    				    
	    			    				    
	    			    				    
	    			    				    title: [{
	    			    				        text: '扫描情况',
	    			    				        x: '15%',
	    			    				        y: '15%',
	    			    				        textAlign: 'center'
	    			    				    }, {
	    			    				        text: 'SKU占比',
	    			    				        x: '60%',
	    			    				        y: '15%',
	    			    				        textAlign: 'center'
	    			    				    }],
	    			    				    
	    			    				    
	    			    				    legend: {
	    			    				        orient: 'vertical',
	    			    				        x: 'left',
	    			    				        data:data1,
	    			    				        show:false
	    			    				    },
	    			    				    
	    			    				    series: [
	    			    				        {
	    			    				            name:'访问来源',
	    			    				            type:'pie',
	    			    				            center : ['15%', '40%'],
	    			    				            radius: ['40%', '55%'],
	    			    				            label: {
	    			    				                normal: {
	    			    				                    formatter: '  {b|{b}：}{c}  {per|{d}%}  ',
	    			    				                    backgroundColor: '#eee',
	    			    				                    borderColor: '#aaa',
	    			    				                    borderWidth: 1,
	    			    				                    borderRadius: 2,
	    			    				                    rich: {
	    			    				                        bper:{
	    			    				                            fontSize: 14
	    			    				                        },
	    			    				                        b: {
	    			    				                            lineHeight: 33
	    			    				                        },
	    			    				                        per: {
	    			    				                            color: '#eee',
	    			    				                            backgroundColor: '#334455',
	    			    				                            padding: [2, 4],
	    			    				                            borderRadius: 2
	    			    				                        }
	    			    				                    }
	    			    				                }
	    			    				            },
	    			    				            data:data2
	    			    				        },{
	    			    				            
	    			    				            name:'访问来源',
	    			    				            type:'pie',
	    			    				            center : ['15%', '40%'],
	    			    				            radius: [0, '30%'],
	    			    				            // label: {
	    			    				            //     normal: {

	    			    				            //         formatter: '  {b|{b}：}{c}  {per|{d}%}  ',
	    			    				            //         backgroundColor: '#eee',
	    			    				            //         borderColor: '#aaa',
	    			    				            //         borderWidth: 1,
	    			    				            //         borderRadius: 2,
	    			    				            //         rich: {
	    			    				            //             bper:{
	    			    				            //                 fontSize: 14
	    			    				            //             },
	    			    				            //             b: {
	    			    				            //                 lineHeight: 33
	    			    				            //             },
	    			    				            //             per: {
	    			    				            //                 color: '#eee',
	    			    				            //                 backgroundColor: '#334455',
	    			    				            //                 padding: [2, 4],
	    			    				            //                 borderRadius: 2
	    			    				            //             }
	    			    				            //         }
	    			    				            //     }
	    			    				            // },
	    			    				            
	    			    				            
	    			    				            label: {
	    			    				                normal: {
	    			    				                    position: 'inner',
	    			    				                    formatter: '{b}\n{c}'
	    			    				                }
	    			    				            },
	    			    				            labelLine: {
	    			    				                normal: {
	    			    				                    show: false
	    			    				                }
	    			    				            },
	    			    				            
	    			    				            data:data3
	    			    				        },
	    			    				                {
	    			    				            name:'访问来源1',
	    			    				            type:'pie',
	    			    				            selectedMode: 'single',
	    			    				            center : ['60%', '40%'],

	    			    				            radius: [0, '55%'],
	    			    				            label: {
	    			    				                normal: {
	    			    				                    formatter: '  {b|{b}：}{c}  {per|{d}%}  ',
	    			    				                    backgroundColor: '#eee',
	    			    				                    borderColor: '#aaa',
	    			    				                    borderWidth: 1,
	    			    				                    borderRadius: 2,
	    			    				                    rich: {
	    			    				                        bper:{
	    			    				                            fontSize: 8
	    			    				                        },
	    			    				                        b: {
	    			    				                            lineHeight: 33
	    			    				                        },
	    			    				                        per: {
	    			    				                            color: '#eee',
	    			    				                            backgroundColor: '#334455',
	    			    				                            padding: [2, 4],
	    			    				                            borderRadius: 2
	    			    				                        }
	    			    				                    }
	    			    				                }
	    			    				            },
	    			    				            data:data4
	    			    				        }
	    			    				    ]
	    			    				};
	    			    		 myChart.setOption(option);
	    			    	}		    	
	    			    }
	    			});
	    		 $("#main").css("display",'block');
	    		check("checkResourceTable",arr);
	    		
	    	};
	    }
	});
	
	
	
});


$("#phoneConn").click(function(){
	$("#conn").attr({"disabled":"disabled"});
	$("#phoneConn").css({'background-color':'black'});
	$.ajax({
	    type : "post",
	    url : ctx+"/statistics/getIp?label="+"wireless", //此次url改为真正需要的url
	    success : function(data) {						    	
	    	ip=data;
	    	ws = new WebSocket("ws://"+ip+":54321/RFID/");
	    	ws.onopen = function()
	    	{
	    	   // Web Socket 已连接上，使用 send() 方法发送数据
	    		//ws.send("发送数据");
	    	   $("#isConnect").html("true");	   
	    	}; 
	    	ws.onmessage = function (evt) 
	    	{ 
	    	   var received_msg = evt.data;
	    		if(arr.indexOf(received_msg)==-1){
	    		   arr.push(received_msg)
	    		   $("#resourceIds").empty();
	    		   $("#resourceIds").val(arr.join(','));
	    		   var obj=new Object()
	    		   obj.id=received_msg;
	    		   json.push(obj);
	    		   $("#checkResourceTable").bootstrapTable('destroy');
	    		   $('#checkResourceTable').bootstrapTable({
	    			    data:json,
	    			    columns: [{
	    		       	 field: 'state',
	    			        title: '异常状态',
	    			        sortable: true	
	    			    }
	    				,{
	    			        field: 'id',
	    			        title: '资源编号',
	    			        sortable: true	       
	    			    }
	    				,{
	    			        field: 'productName',
	    			        title: 'sku',
	    			        sortable: true	       
	    			    },{
	    			        field: 'firstType',
	    			        title: '一级类目',
	    			        sortable: true	       
	    			    },{
	    			        field: 'secondType',
	    			        title: '二级类目',
	    			        sortable: true	       
	    			    },{
	    			        field: 'thirdType',
	    			        title: '三级类目',
	    			        sortable: true	       
	    			    },{
	    			        field: 'warehouseName',
	    			        title: '仓库名称',
	    			        sortable: true	       
	    			    },{
	    			        field: 'warehouseTypeName',
	    			        title: '仓库类型',
	    			        sortable: true	       
	    			    },{
	    			        field: 'evidenceLock',
	    			        title: '凭据锁',
	    			        sortable: true	
	    			        ,formatter:function(value, row , index){
	    		        	   if (row.evidenceLock == "0") {
	    		                   return "解锁";
	    		               }  
	    		        	   if (row.evidenceLock == "1") {
	    		                   return "锁定";
	    		               }  
	    			         }
	    			    }	
	    			     ]
	    			});
	    		   
	    		}
	    	};
	    	ws.onclose = function (evt) 
	    	{ 
	    		var arr=$("#resourceIds").val().split(",");
	    		$("#checkResourceTable").bootstrapTable('destroy');
	    		var data1=["总量","扫描正常","扫描异常"];
	    		var data2=[];
	    		var data3=[];
	    		var data4=[];
	    		 
	    		 $.ajax({
	    			    url:ctx+"/resource/findResourceCountByIds?ids="+arr,
	    			    type:"post",	   
	    			    success:function(data){
	    			    	if(data !=null && data != ''){
	    			    		var obj1=new Object();
	    			    		var obj2=new Object();
	    			    		var obj3=new Object();
	    			    		obj1.name="扫描正常";
	    			    		obj1.value=data.totalCurrectCount;
	    			    		obj2.name="扫描异常";
	    			    		obj2.value=data.totalErrorCount;
	    			    		obj3.name="扫描总量";
	    			    		obj3.value=data.totalCount;
	    			    		data2.push(obj1);
	    			    		data2.push(obj2);
	    			    		data3.push(obj3);
	    			    		var resCount=data.resourceList;
	    			    		if(resCount != null && resCount != ''){
	    			    			for(var i=0;i<resCount.length;i++){
	    			    				data1.push(resCount[i].productName);
	    			    				var obj4=new Object();
	    			    				obj4.name=resCount[i].productName;
	    					    		obj4.value=resCount[i].count;
	    					    		data4.push(obj4);
	    			    			}
	    			    		}
	    			    		var myChart = echarts.init(document.getElementById('main'));
	    			    		 option = {
	    			    				    tooltip: {
	    			    				        trigger: 'item',
	    			    				        formatter: "{b}: {c} ({d}%)"
	    			    				    },
	    			    				    
	    			    				    
	    			    				    
	    			    				    title: [{
	    			    				        text: '扫描情况',
	    			    				        x: '15%',
	    			    				        y: '15%',
	    			    				        textAlign: 'center'
	    			    				    }, {
	    			    				        text: 'SKU占比',
	    			    				        x: '60%',
	    			    				        y: '15%',
	    			    				        textAlign: 'center'
	    			    				    }],
	    			    				    
	    			    				    
	    			    				    legend: {
	    			    				        orient: 'vertical',
	    			    				        x: 'left',
	    			    				        data:data1,
	    			    				        show:false
	    			    				    },
	    			    				    
	    			    				    series: [
	    			    				        {
	    			    				            name:'访问来源',
	    			    				            type:'pie',
	    			    				            center : ['15%', '40%'],
	    			    				            radius: ['40%', '55%'],
	    			    				            label: {
	    			    				                normal: {
	    			    				                    formatter: '  {b|{b}：}{c}  {per|{d}%}  ',
	    			    				                    backgroundColor: '#eee',
	    			    				                    borderColor: '#aaa',
	    			    				                    borderWidth: 1,
	    			    				                    borderRadius: 2,
	    			    				                    rich: {
	    			    				                        bper:{
	    			    				                            fontSize: 14
	    			    				                        },
	    			    				                        b: {
	    			    				                            lineHeight: 33
	    			    				                        },
	    			    				                        per: {
	    			    				                            color: '#eee',
	    			    				                            backgroundColor: '#334455',
	    			    				                            padding: [2, 4],
	    			    				                            borderRadius: 2
	    			    				                        }
	    			    				                    }
	    			    				                }
	    			    				            },
	    			    				            data:data2
	    			    				        },{
	    			    				            
	    			    				            name:'访问来源',
	    			    				            type:'pie',
	    			    				            center : ['15%', '40%'],
	    			    				            radius: [0, '30%'],
	    			    				            // label: {
	    			    				            //     normal: {

	    			    				            //         formatter: '  {b|{b}：}{c}  {per|{d}%}  ',
	    			    				            //         backgroundColor: '#eee',
	    			    				            //         borderColor: '#aaa',
	    			    				            //         borderWidth: 1,
	    			    				            //         borderRadius: 2,
	    			    				            //         rich: {
	    			    				            //             bper:{
	    			    				            //                 fontSize: 14
	    			    				            //             },
	    			    				            //             b: {
	    			    				            //                 lineHeight: 33
	    			    				            //             },
	    			    				            //             per: {
	    			    				            //                 color: '#eee',
	    			    				            //                 backgroundColor: '#334455',
	    			    				            //                 padding: [2, 4],
	    			    				            //                 borderRadius: 2
	    			    				            //             }
	    			    				            //         }
	    			    				            //     }
	    			    				            // },
	    			    				            
	    			    				            
	    			    				            label: {
	    			    				                normal: {
	    			    				                    position: 'inner',
	    			    				                    formatter: '{b}\n{c}'
	    			    				                }
	    			    				            },
	    			    				            labelLine: {
	    			    				                normal: {
	    			    				                    show: false
	    			    				                }
	    			    				            },
	    			    				            
	    			    				            data:data3
	    			    				        },
	    			    				                {
	    			    				            name:'访问来源1',
	    			    				            type:'pie',
	    			    				            selectedMode: 'single',
	    			    				            center : ['60%', '40%'],

	    			    				            radius: [0, '55%'],
	    			    				            label: {
	    			    				                normal: {
	    			    				                    formatter: '  {b|{b}：}{c}  {per|{d}%}  ',
	    			    				                    backgroundColor: '#eee',
	    			    				                    borderColor: '#aaa',
	    			    				                    borderWidth: 1,
	    			    				                    borderRadius: 2,
	    			    				                    rich: {
	    			    				                        bper:{
	    			    				                            fontSize: 8
	    			    				                        },
	    			    				                        b: {
	    			    				                            lineHeight: 33
	    			    				                        },
	    			    				                        per: {
	    			    				                            color: '#eee',
	    			    				                            backgroundColor: '#334455',
	    			    				                            padding: [2, 4],
	    			    				                            borderRadius: 2
	    			    				                        }
	    			    				                    }
	    			    				                }
	    			    				            },
	    			    				            data:data4
	    			    				        }
	    			    				    ]
	    			    				};
	    			    		 myChart.setOption(option);
	    			    	}		    	
	    			    }
	    			});
	    		 $("#main").css("display",'block');
	    		check("checkResourceTable",arr);	    		
	    	};
	    }
	});
	
	
	
});



$("#close").click(function(){
	$("#conn").removeAttr("disabled");
	$("#phoneConn").removeAttr("disabled");
	$("#phoneConn").css({'background-color':'#3ca2e0'});
	$("#conn").css({'background-color':'#3ca2e0'});
	ws.close();
	$("#isConnect").html("false");
	
});
$("#clear").click(function(){
	 $("#resourceIds").val("");
	 $("#checkResourceTable").bootstrapTable('destroy');
	 arr=[];
	 json=[];
	 $("#main").css("display",'none');
});
})